<?php

/**
 * Created on 24 mai 2011
 *  * @author Samy Deghou(deghou@polytech.unice.fr ; deghou@embl.de)
 * 		   Stephan Beisken (beisken@ebi.ac.uk)
 * 		   Luis Felipe De Figueiredo (ldpf@ebi.ac.uk)
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class MoleculeSpectrum implements iCRUD {
    /*
     * Attributes
     */

    private $_moleculeID;
    private $_spectrumID;
    private $_type;

    /*
     * Constructor
     */

    public function MoleculeSpectrum($type, $moleculeID = -1, $spectrumID = -1) {

        $this->_moleculeID = $moleculeID;
        $this->_spectrumID = $spectrumID;
        $this->_type = $type;
    }

    public function get_moleculeID() {
        return $this->_moleculeID;
    }

    public function set_moleculeID($_moleculeID) {
        $this->_moleculeID = $_moleculeID;
    }

    public function get_spectrumID() {
        return $this->_spectrumID;
    }

    public function set_spectrumID($_spectrumID) {
        $this->_spectrumID = $_spectrumID;
    }

    public function get_type() {
        return $this->_type;
    }

    public function set_type($_type) {
        $this->_type = $_type;
    }

    /*
     * CRUD
     */

    /**
     * Put an object in the database
     */
    public function create() {
        Database::connect();
        if ($this->_moleculeID != -1 && $this->_spectrumID)
            die("Unable to create, still existing !");
        else {
            $query = "INSERT INTO `MOLECULE_SPECTRUM` values ('" .
                    $this->_moleculeID . "','" .
                    $this->_spectrumID . "')";
            mysql_query($query) or die(mysql_error());
            $this->_idSujet = mysql_insert_id();
        }
        Database::disconnect();
    }

    /**
     * Read an object from the database
     */
    public static function read($key) {
        Database::connect();
        $query = "SELECT * FROM MOLECULE_SPECTRUM WHERE molecule_id = '" .
                $key[0] . "' AND spectrum_id ='" . $key[1] . "'";
        $ans = mysql_fetch_assoc(mysql_query($query));
        extract($ans);
        Database::disconnect();
        return new SignalAtom($type, $molecule_id, $spectrum_id);
        Database::disconnect();
    }

    /**
     * Update an object from the database
     */
    public function update() {
        Database::connect();

        Database::disconnect();
    }

    /**
     * Delete an object from the database
     */
    public function delete() {
        Database::connect();
        $query = "DELETE FROM `SIGNAL_ATOM` WHERE molecule_id='" .
                $this->_moleculeID . "' AND spectrum_id = '" .
                $this->_spectrumID . ".";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

}
?>
